package org.shejko.util.splitunite;

import java.util.ArrayList;
import java.util.Collection;

/**
 * An adapter over ISplitUnite implementation that provides more convenient interface
 * for usage than ISplitUnite itself. (While ISplitUnite is designed to be convenient for implementor).
 * 
 * @author dmytros
 */
public class SplitUniteHelper
{
    private final ISplitUnite splitunite_;

    public SplitUniteHelper(ISplitUnite splitunite)
    {
        splitunite_ = splitunite;
    }

    public ISplitUnite getSplitUnite()
    {
        return splitunite_;
    }

    public <C extends Collection<String>> C split(String str, C col)
    {
        return split(getSplitUnite(), str, col);
    }

    public static <C extends Collection<String>> C split(ISplitUnite splitunite, String str, C col)
    {
        splitunite.split(str, col);
        return col;
    }

    public StringBuilder unite(Collection<String> col, StringBuilder builder)
    {
        return unite(getSplitUnite(), col, builder);
    }

    public static StringBuilder unite(ISplitUnite splitunite, Collection<String> col, StringBuilder builder)
    {
        splitunite.unite(col, builder);
        return builder;
    }

    public ArrayList<String> split(String str)
    {
        return split(getSplitUnite(), str);
    }

    public static ArrayList<String> split(ISplitUnite splitunite, String str)
    {
        return split(splitunite, str, new ArrayList<String>());
    }

    public String unite(Collection<String> col)
    {
        return unite(getSplitUnite(), col);
    }

    public static String unite(ISplitUnite splitunite, Collection<String> col)
    {
        return unite(splitunite, col, new StringBuilder()).toString();
    }
}
